<?php
//add custom category ben ngoai category 
add_action('category_add_form_fields', 'add_fields_category_custom');
add_action('create_term', 'category_custom_save_fields');
//add custom category ben trong category khi edit
add_action('edit_term', 'category_custom_save_fields');
add_action('category_edit_form_fields', 'edit_fields_category_custom');

// Begin add custom field of category
function add_fields_category_custom($taxonomy)
{	?>
	<div class="form-field">
    	<label for="tag_image">Thumbnail</label>
        <input type="text" name="tag_image" id="tag_image" onclick="uploadGallery('tag_image')" value="" />	
    </div>
    <?php
}
function edit_fields_category_custom($taxonomy)
{	?>
    <tr class="form-field">
		<th scope="row" valign="top"><label for="tag_image">Thumbnail</label></th>
		<td><input type="text" name="tag_image" id="tag_image" onclick="uploadGallery('tag_image')" value="<?php echo get_option('_tag_image'. $taxonomy->term_id); ?>" /></td>
	</tr>
    <?php
}
//edit_$taxonomy
function category_custom_save_fields($term_id)
{
	$tag_image	= get_option('_tag_image'. $term_id);
	
    if( !empty($_POST['tag_image']) )
		update_option('_tag_image'. $term_id, $_POST['tag_image']);
	elseif( !empty($tag_image) )
		delete_option('_tag_image'. $term_id);
}
// End
?>